package com.andy.blog.admin.controller;

import com.andy.blog.admin.dto.CategoryDTO;
import com.andy.blog.admin.service.CategoryBusService;
import com.andy.blog.common.annotation.Log;
import com.andy.blog.common.enums.BusinessTypeEnum;
import com.andy.blog.common.page.PageUtilsDTO;
import com.andy.blog.common.reponse.GeneralResponseResult;
import com.andy.blog.dal.vo.CategoryVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by andy on 2023/6/21 12:42
 */
@RestController
public class CategoryController {

    @Resource
    private CategoryBusService categoryBusService;

    /**
     * 根据条件分页查询
     */
    //@PreAuthorize("@ss.hasPermi('system:dict:list')")
    @GetMapping("/article/category/selectListByPage")
    public GeneralResponseResult<PageUtilsDTO<CategoryDTO>> selectListByPage(CategoryVO categoryVO) {
        return GeneralResponseResult.success(categoryBusService.selectListByPage(categoryVO));
    }

    /**
     * 条件查询
     */
    @GetMapping("/article/category/selectList")
    public GeneralResponseResult<List<CategoryDTO>> selectList(CategoryVO categoryVO) {
        return GeneralResponseResult.success(categoryBusService.selectList(categoryVO));
    }

    /**
     * 新增
     */
    @Log(title = "分类管理", businessType = BusinessTypeEnum.INSERT)
    @PostMapping("/article/category/addCategory")
    public GeneralResponseResult<Void> addCategory(@Validated @RequestBody CategoryVO categoryVO) {
        categoryBusService.addCategory(categoryVO);
        return GeneralResponseResult.success();
    }

    /**
     * 查询分类详细
     */
    //@PreAuthorize("@ss.hasPermi('system:dict:query')")
    @GetMapping(value = "/article/category/{id}")
    public GeneralResponseResult<CategoryDTO> getById(@PathVariable Long id) {
        return GeneralResponseResult.success(categoryBusService.selectCategoryById(id));
    }

    /**
     * 修改分类
     */
    //@PreAuthorize("@ss.hasPermi('system:dept:edit')")
    @Log(title = "分类管理", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping("/article/category")
    public GeneralResponseResult<Void> updateCategory(@Validated @RequestBody CategoryVO categoryVO) {
        categoryBusService.updateCategory(categoryVO);
        return GeneralResponseResult.success();
    }

    //@VisitLogger(value = "文章分类")
    //@ApiOperation(value = "查看分类列表")
    @GetMapping("/portal/category/list")
    public GeneralResponseResult<List<CategoryDTO>> listCategoryVO() {
        return GeneralResponseResult.success(categoryBusService.listCategoryVO());
    }
}
